// defHttp就是封装好的发送请求函数
import { defHttp } from '/@/utils/http/axios';
// 数据类型 - 定义响应返回值数据的类型
import type {
  GetSpuListResultModel,
  GetSpuListParamsModel,
  BaseSaleAttrListModel,
  SpuModel,
  SpuImageListModel,
  SpuSaleAttrListModel,
} from './model/spuModel';

// 枚举：定义请求地址的
enum Api {
  GetSpuList = '/admin/product',
  GetBaseSaleAttrList = '/admin/product/baseSaleAttrList',
  SaveSpu = '/admin/product/saveSpuInfo',
  RemoveSpu = '/admin/product/deleteSpu',
  GetSpuImageList = '/admin/product/spuImageList',
  GetSpuSaleAttrList = '/admin/product/spuSaleAttrList',
  UpdateSpu = '/admin/product/updateSpuInfo',
}

// 更新spu
export const updateSpuApi = (data: SpuModel) => {
  return defHttp.post<null>({
    url: Api.UpdateSpu,
    data,
  });
};

// 获取getSpuSaleAttrList
export const getSpuSaleAttrListApi = (id: number) => {
  return defHttp.get<SpuSaleAttrListModel>({
    url: Api.GetSpuSaleAttrList,
    params: `/${id}`,
  });
};

// 获取SpuImageList
export const getSpuImageListApi = (id: number) => {
  return defHttp.get<SpuImageListModel>({
    url: Api.GetSpuImageList,
    params: `/${id}`,
  });
};

// 删除Spu
export const removeSpuApi = (id: number) => {
  return defHttp.delete<null>({
    url: Api.RemoveSpu,
    params: `/${id}`,
  });
};

// 获取基础销售属性列表
export const saveSpuApi = (data: SpuModel) => {
  return defHttp.post<null>({
    url: Api.SaveSpu,
    data,
  });
};

// 获取基础销售属性列表
export const getBaseSaleAttrListApi = () => {
  return defHttp.get<BaseSaleAttrListModel>({
    url: Api.GetBaseSaleAttrList,
  });
};

// 获取SPU列表
export const getSpuListApi = ({ page, limit, category3Id }: GetSpuListParamsModel) => {
  return defHttp.get<GetSpuListResultModel>({
    url: Api.GetSpuList,
    params: `/${page}/${limit}`, // 添加path参数
    data: {
      // 添加到query参数
      category3Id,
    },
  });
};
